import 'package:dio/dio.dart';

class AiChatService {
  static final Dio _dio = Dio();

  /// 发送消息
  static Future<Map<String, dynamic>?> sendMessage({
    required String sessionId,
    required String content,
    String? conversationId,
  }) async {
    try {
      final requestData = {
        'bundle_id': 'com.thal.ios',
        'session_id': sessionId,
        'content_type': 'text',
        'content': content,
      };

      // 如果有会话ID，添加到请求中
      if (conversationId != null && conversationId.isNotEmpty) {
        requestData['conversation_id'] = conversationId;
      }

      final response = await _dio.post(
        'https://api.wiseaii.com/wiseai/v1/chat',
        data: requestData,
        options: Options(headers: {'Content-Type': 'application/json'}),
      );

      if (response.statusCode == 200) {
        final data = response.data;
        if (data['code'] == 1003) {
          return data['data'];
        }
      }
      return null;
    } catch (e) {
      print('AI Chat API Error: $e');
      return null;
    }
  }
}
